home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CASample / TraceLog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  1.3 KB  |  94 lines  |  [TEXT/MPS ]

  1.  
  2. #include "TraceLog.h"
  3. #include <PLStringFuncs.h>
  4. #include <Files.h>
  5. #include <Events.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <stdarg.h>
  9.  
  10.  
  11. short    traceLogRefNum;
  12. FSSpec    logSpec;
  13.  
  14.  
  15. void Trace_StartLog(FSSpec* spec, Boolean flushLog)
  16. {
  17. FInfo    ignore;
  18.  
  19.     if (spec == NULL)
  20.     {
  21.         PLstrcpy (logSpec.name, "\pCASample Trace Log");
  22.         logSpec.vRefNum = 0;
  23.         logSpec.parID = 2;
  24.     }
  25.     else
  26.     {
  27.         logSpec = *spec;
  28.     }
  29.     
  30.     if (FSpGetFInfo (&logSpec, &ignore))
  31.     {
  32.         FSpCreate (&logSpec, 'ttxt', 'TEXT', 0);
  33.     }
  34.     
  35.     FSpOpenDF (&logSpec, fsRdWrPerm, &traceLogRefNum);
  36.     
  37.     if (flushLog)
  38.         SetEOF (traceLogRefNum, 0);
  39.         
  40. }
  41.  
  42.  
  43.  
  44. void Trace_StopLog()
  45. {
  46.     FSClose (traceLogRefNum);
  47. }
  48.  
  49. void Trace_Log (char* str)
  50. {
  51. long    count;
  52. char    eol[2];
  53. char    line[256];
  54. long    eof;
  55.  
  56.  
  57.     FSpOpenDF (&logSpec, fsRdWrPerm, &traceLogRefNum);
  58.     GetEOF (traceLogRefNum, &eof);
  59.     SetFPos (traceLogRefNum, fsFromStart, eof);
  60.     
  61.     count = strlen (str) + 1;
  62.  
  63.     FSWrite (traceLogRefNum, &count, str);
  64.     
  65.     count = 1;
  66.     eol[0] = 0x0D;
  67.     FSWrite (traceLogRefNum, &count, eol);
  68.     
  69.     FSClose(traceLogRefNum);
  70.     
  71.     
  72. }
  73.  
  74. void _CASTrace(short traceLevel,  char *fmt, ... )
  75. {
  76.     va_list args;
  77.  
  78.     if (traceLevel >= TRACELEVEL)
  79.     {
  80.     
  81.         char msg[512];
  82.         strcpy(msg, "Log: ");
  83.         va_start(args,fmt);
  84.         vsprintf(msg+strlen(msg),fmt,args);
  85.         va_end(args);
  86.         strcat (msg, "");
  87.         
  88.         Trace_Log (msg);
  89.         
  90.     }
  91.         
  92. }
  93.  
  94.